package com.moli.iov.down.config;

import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

/**
 * <p>
 * activeMQ
 * </p>
 *
 * @author zql
 * @since 2019/9/16 13:09
 */
@Configuration
public class ActiveMqConfig {

  @Value("${activemq.delay.queue}")
  private String activemqDelayqueue;

  @Value("${service.group}")
  private String group;

  @Autowired
  private TaskExecutor taskExecutor;

  @Bean("delayQueue")
  public Queue queue(){
    return new ActiveMQQueue(activemqDelayqueue + "-" + group);
  }

  /**
   * 处理queue消息
   * @param connectionFactory
   * @return
   */
  @Bean
  public JmsListenerContainerFactory queueListenerFactory(ConnectionFactory connectionFactory) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setPubSubDomain(false);
    factory.setConnectionFactory(connectionFactory);
    factory.setTaskExecutor(taskExecutor);
    return factory;
  }
}
